﻿using System;
using System.Collections.Generic;
using System.Text;
using Pahan.McuFusion.Common;

namespace Pahan.McuFusion.Files
{
    public sealed class FileTypeInfo
    {
        public FileTypeInfo(String extension) : this(extension, null)
        {
        }
        
        public FileTypeInfo(String extension, String description)
        {
            extension = extension.TrimStart('.');
            Assert.NotNullOrEmpty(extension, "extension");
            this.extension = extension;
            this.description = String.IsNullOrEmpty(description) ?
                String.Format("*.{0} files", extension) :
                description;
        }

        public String Extension
        {
            get { return extension; }
        }

        public String Description
        {
            get { return description; }
        }

        public override bool Equals(object obj)
        {
            var other = obj as FileTypeInfo;
            if (other == null)
                return false;

            return Comparer.Equals(this.extension, other.extension);
        }

        public override int GetHashCode()
        {
            return Comparer.GetHashCode(this.extension);
        }

        private static StringComparer Comparer
        {
            get
            {
                return StringComparer.InvariantCultureIgnoreCase;
            }
        }

        private readonly string extension;

        private readonly string description;
    }
}
